{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "LNfAROLDPn4Y"
   },
   "source": [
    "# Numpy \n",
    "\n",
    "\n",
    "\n",
    "* Basic library used in scientific calculations\n",
    "\n",
    "* Linear algebra, machine learning, data science\n",
    "\n",
    "* Multi-dimensional arrays\n",
    "\n",
    "* Fast access to multidimensional arrays\n",
    "\n",
    "* The difference from the lists is having a fixed size.\n",
    "\n",
    "\n",
    "![numpy.PNG]()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "oaFwqdSgPJYE"
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "57ve9sX-P7Le"
   },
   "outputs": [],
   "source": [
    "a = np.array([1,2,3,4,5])   # 1st-degree array, vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "IYrYD-DIQJiw",
    "outputId": "81dbb41b-399d-4a28-d455-265437ddfaa2"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "50Cr6wPdQL9u",
    "outputId": "cb5c2e1d-cc9c-4aae-9692-4a2b7a8468b6"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5,)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "UBwXn9SfQPdb",
    "outputId": "1a545220-7f56-4efd-bc87-c8b95e8642d5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.ndim    # return the dimension of an array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "eM2FHcT4QWge",
    "outputId": "742f28bc-30fb-49e9-852d-2fc4b489793a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "print(a[0])\n",
    "print(a[3])\n",
    "print(a[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "3GqnJxZRQdww",
    "outputId": "8d55f421-5ee1-45d4-fc62-ca846637cc3e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 8 4 5]\n"
     ]
    }
   ],
   "source": [
    "a[2] = 8\n",
    "\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "T4YHqQ25RDWn"
   },
   "outputs": [],
   "source": [
    "b = np.array([[1,2,3,4],\n",
    "              [5,6,7,8]])    #2nd-degree array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "T1a-6fsjRZ-u",
    "outputId": "3d59e0b6-c4f3-4259-bae1-6673a611685c"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4],\n",
       "       [5, 6, 7, 8]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "cYIkw2VVRlT7",
    "outputId": "84afd9e0-ee91-4427-a266-7eccebaaf600"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "EaKBwnAlRozK",
    "outputId": "41315af3-4a46-4580-9ea8-584a52a6bdf4"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 4)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.shape    # 2nd-degree array with 2 row, 4 col."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4],\n",
       "       [5, 6, 7, 8]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "4AGngEh7Rrzb",
    "outputId": "4ac85f3d-ec2f-4481-d8d1-b57c82fd1371"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "print(b[0,0])      \n",
    "print(b[1,0])      \n",
    "print(b[1,1])      #1st item of 1st row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "sfj3k0nASWd5",
    "outputId": "1a3e9004-6fe2-4a47-ff3a-2c5950c004ab"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 5 6\n"
     ]
    }
   ],
   "source": [
    "print(b[0,0],b[1,0],b[1,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "B7CWo6x7ScGt"
   },
   "outputs": [],
   "source": [
    "c = np.array([[1,2,3],\n",
    "              [4,5,6],\n",
    "              [7,8,9]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "BJolEGVYTku5",
    "outputId": "0894f466-590b-46bf-b7cb-45d0a4305bd4"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "jB6xZrrSTl91",
    "outputId": "9ab0e76b-dff2-4447-8dc3-4a03ff36c090"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "PQiTSvuyTqHo",
    "outputId": "cc475b70-2a1f-401b-9d4e-732d529508ac"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "tzR7JdjfVW2O"
   },
   "outputs": [],
   "source": [
    "d = np.array([[[1,2,3],\n",
    "               [4,5,6],\n",
    "               [7,8,9]]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "MReC1memVgiv",
    "outputId": "1b59f141-fba0-430e-d059-2971b3a81217"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[1, 2, 3],\n",
       "        [4, 5, 6],\n",
       "        [7, 8, 9]]])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "iyKawQGfViJ4",
    "outputId": "e7fdc5fc-5242-4849-f671-543e31c5c300"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.ndim   # 3-dimension array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "jr47fZl9VnH0",
    "outputId": "16e6b0cb-920d-49eb-b722-2903cc28618c"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 3, 3)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "yjdoyhzSV7Ic",
    "outputId": "fe8e05aa-c2c8-478d-c857-83f83e8b987d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[0,1,1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "mU7pzvKMWQO4"
   },
   "source": [
    "### Arrays with Special Values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "-dGCcLvSWMr2",
    "outputId": "dbf87acb-0cd5-4590-929c-56a092664f4d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0.]\n",
      " [0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "#Zero Array\n",
    "\n",
    "\n",
    "s = np.zeros((2,2))\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "hf_AtIYYWkvZ",
    "outputId": "d09ecdaa-b6db-4a69-98e3-10beb8a1de47"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int64\n"
     ]
    }
   ],
   "source": [
    "s2 = np.ones((2,3)).astype(\"int64\").dtype\n",
    "\n",
    "print(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1. 1. 1.]\n",
      " [1. 1. 1.]]\n"
     ]
    }
   ],
   "source": [
    "s2 = np.ones((2,3))\n",
    "print(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "vx3qexEqWvL1",
    "outputId": "ea2d52db-607f-48c0-de2b-d70a0120f28c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[8 8 8]\n",
      " [8 8 8]\n",
      " [8 8 8]]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "s3 = np.full((3,3),8)\n",
    "\n",
    "print(s3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 159
    },
    "colab_type": "code",
    "id": "E9R0MuxNW4e-",
    "outputId": "7e3c63cc-f910-4963-a881-1d7e0b10a737"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9.27679712e-312 6.27463370e-322 0.00000000e+000 0.00000000e+000\n",
      "  1.42417900e-306]\n",
      " [5.30276956e+180 1.57076922e-076 4.57487963e-071 4.66499561e-086\n",
      "  3.35959356e-143]\n",
      " [6.01433264e+175 6.93885958e+218 5.56218858e+180 3.94356143e+180\n",
      "  3.72782491e-057]\n",
      " [7.80064249e-043 6.52055591e-042 9.35008708e-067 4.41198586e-143\n",
      "  1.50008929e+248]]\n"
     ]
    }
   ],
   "source": [
    "# It creates a series of randomly determined elements according to the state of the memory.\n",
    "\n",
    "s4 = np.empty((4,5))\n",
    "\n",
    "print(s4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 88
    },
    "colab_type": "code",
    "id": "qFKWO-IMXZzq",
    "outputId": "536ce149-e413-4217-b4ee-e43240deb491"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1. 0. 0. 0.]\n",
      " [0. 1. 0. 0.]\n",
      " [0. 0. 1. 0.]\n",
      " [0. 0. 0. 1.]]\n"
     ]
    }
   ],
   "source": [
    "#diagonal array\n",
    "\n",
    "s5 = np.eye(4)\n",
    "\n",
    "print(s5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "nSwJ1RbGYDWa",
    "outputId": "2bcfce3d-13aa-4433-b3dd-fc2856e5a921"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "s7 = np.arange(0,10,1)   \n",
    "\n",
    "print(s7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "1jtSOsmAY1pQ",
    "outputId": "b5b3fe57-aaef-40da-8f01-d58714944065"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.   2.25 2.5  2.75 3.  ]\n"
     ]
    }
   ],
   "source": [
    "s8 = np.linspace(2,3,5)\n",
    "\n",
    "print(s8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 106
    },
    "colab_type": "code",
    "id": "DUmuguakX1em",
    "outputId": "2f51779e-4771-4441-b9db-7b1d7abec17b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.76340755 0.53471369 0.46762585 0.85171004 0.95582832]\n",
      " [0.70299103 0.15913386 0.7042347  0.38874101 0.93434943]\n",
      " [0.78667396 0.61890382 0.4776483  0.22138073 0.45374143]\n",
      " [0.57427484 0.7634074  0.71862918 0.15050893 0.37722183]\n",
      " [0.27245849 0.2875156  0.25576563 0.28632725 0.64980458]]\n"
     ]
    }
   ],
   "source": [
    "s6 = np.random.random((5,5))      \n",
    "\n",
    "print(s6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "GPlviTndZlNs",
    "outputId": "cd5385e5-f25b-4249-9945-2f36d5bd46fd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10,)"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array_random = np.random.randint(5,10, size = 10)\n",
    "array_random.shape "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 88
    },
    "colab_type": "code",
    "id": "-EqS5efhZ51Y",
    "outputId": "90ba1836-5fc4-40d1-d0fc-8d005e5881a5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[8, 9, 7, 7],\n",
       "       [7, 8, 7, 8],\n",
       "       [8, 6, 8, 6],\n",
       "       [6, 8, 6, 8]])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(5,10, size= (4,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 124
    },
    "colab_type": "code",
    "id": "CJtE67kOaIBS",
    "outputId": "e03e0b13-f6e5-4957-c57b-c867ced373df"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[7 6 6]\n",
      " [7 7 9]\n",
      " [8 6 8]\n",
      " [9 5 8]\n",
      " [8 7 9]]\n",
      "(5, 3)\n"
     ]
    }
   ],
   "source": [
    "#reshape\n",
    "\n",
    "d2 = np.random.randint(5,10, size = (5,3))\n",
    "\n",
    "print(d2)\n",
    "\n",
    "print(d2.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "-v1N5u1xaW3I",
    "outputId": "c42a8bfe-bd51-4a71-fe07-324a34332a43"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7, 6, 6, 7, 7],\n",
       "       [9, 8, 6, 8, 9],\n",
       "       [5, 8, 8, 7, 9]])"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.reshape(3,5)   #The original matrix and the new one must have the same number of items."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7],\n",
       "       [6],\n",
       "       [6],\n",
       "       [7],\n",
       "       [7],\n",
       "       [9],\n",
       "       [8],\n",
       "       [6],\n",
       "       [8],\n",
       "       [9],\n",
       "       [5],\n",
       "       [8],\n",
       "       [8],\n",
       "       [7],\n",
       "       [9]])"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.reshape(15,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 106
    },
    "colab_type": "code",
    "id": "E3fF-kX0bEZc",
    "outputId": "0b31361d-e5d5-4d98-f7f9-60f93d2f3aef"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9 9 8]\n",
      " [5 8 6]\n",
      " [5 5 7]\n",
      " [9 7 8]\n",
      " [9 9 7]]\n"
     ]
    }
   ],
   "source": [
    "d3 =  np.random.randint(5,10, size = (5,3))\n",
    "\n",
    "print(d3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "VWznb1VccVbX",
    "outputId": "ffb8bc61-a09c-4afd-a58f-f2af5dfc8bd8"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9 9 8 5 8 6 5 5 7 9 7 8 9 9 7]\n"
     ]
    }
   ],
   "source": [
    "d3 = d3.ravel()\n",
    "\n",
    "print(d3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "at5eOfDpccRi",
    "outputId": "0670e23f-a82b-453b-9a80-ad510200c2b5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15,)"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "b9iUc78Xcfn2",
    "outputId": "ad4abaa0-f6b0-421d-c9fa-c06d3a9c3685"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([9, 9, 8, 5, 8, 6, 5, 5, 7, 9, 7, 8, 9, 9, 7])"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3.astype(\"int64\").dtype\n",
    "d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "d3 = d3.reshape(3,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[9, 9, 8, 5, 8],\n",
       "       [6, 5, 5, 7, 9],\n",
       "       [7, 8, 9, 9, 7]])"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "2cY50jkVck7x",
    "outputId": "45528b9f-7f73-44d7-a476-e61165cc488b"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "yLZSqxUicn8M",
    "outputId": "1e9bbb85-f712-4c66-c625-686e58d8a65e"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "28AXNm6Ucpgx",
    "outputId": "b1e8b0ba-9b9b-4976-a205-f6d4ee042fab"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7, 8, 9, 9, 7],\n",
       "       [6, 5, 5, 7, 9],\n",
       "       [9, 9, 8, 5, 8]])"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "VW-zH91kcu1C"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[79 20 99 85 42 69 54 24 42 10]\n"
     ]
    }
   ],
   "source": [
    "news = np.random.randint(1,100,10)\n",
    "\n",
    "print(news)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(news)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10,)"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "YfwQ7uwpRyIM"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.argmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "okmEldzoR0W6"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.argmin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "6RAzHt1JR2hf"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "52.4"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "rBXAqPXWR-Z-"
   },
   "source": [
    "## Stacking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "DXGTBaHZR6Oa"
   },
   "outputs": [],
   "source": [
    "a = np.array([[1,2,3],[4,5,6]])\n",
    "\n",
    "b = np.array([[6,5,4], [3,2,1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 5, 4],\n",
       "       [3, 2, 1]])"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "unmWypIcSEfv"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [6, 5, 4],\n",
       "       [3, 2, 1]])"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack((a,b)) #vertical stacking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "f0ZXDE8PSIzh"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 6, 5, 4],\n",
       "       [4, 5, 6, 3, 2, 1]])"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack((a,b)) #horizontal stacking"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "23oZkyItSPYP"
   },
   "source": [
    "## Concatenation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "mTYlzQ48SM0B"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1]\n",
      " [2 3]\n",
      " [4 5]\n",
      " [6 7]\n",
      " [8 9]]\n"
     ]
    }
   ],
   "source": [
    "myArray = np.array([0,1,2,3,4,5,6,7,8,9]).reshape(5,2)\n",
    "\n",
    "print(myArray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "PLGnF7nNSXN7"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1]\n",
      " [2 3]\n",
      " [4 5]\n",
      " [6 7]\n",
      " [8 9]\n",
      " [0 1]\n",
      " [2 3]\n",
      " [4 5]\n",
      " [6 7]\n",
      " [8 9]]\n"
     ]
    }
   ],
   "source": [
    "print(np.concatenate([myArray,myArray], axis = 0))  #vertical "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "qA03GoFRSff7"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 0 1]\n",
      " [2 3 2 3]\n",
      " [4 5 4 5]\n",
      " [6 7 6 7]\n",
      " [8 9 8 9]]\n"
     ]
    }
   ],
   "source": [
    "print(np.concatenate([myArray,myArray], axis = 1)) #horizontal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "ZUmGC9ODSomz"
   },
   "source": [
    "## Slicing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "9L4C-b_ZSlvc"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 3]\n",
      " [6 7]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[1,2,3,4],\n",
    "              [5,6,7,8],\n",
    "              [9,10,11,12]])\n",
    "\n",
    "b = a[:2, 1:3]    \n",
    "\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "wh8r1cEMSuAy"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(a[0,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "k9nAHjvLSwt5"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "77\n"
     ]
    }
   ],
   "source": [
    "b[0,0] = 77    \n",
    "\n",
    "print(a[0,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1, 77,  3,  4],\n",
       "       [ 5,  6,  7,  8],\n",
       "       [ 9, 10, 11, 12]])"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "VRNic9bDSzxr"
   },
   "outputs": [],
   "source": [
    "line1 = a[1,:]    \n",
    "line2 = a[1:2, :]  \n",
    "line3 = a[[1],:]    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "TUexRz5ZS4dh"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 6 7 8] (4,)\n",
      "[[5 6 7 8]] (1, 4)\n",
      "[[5 6 7 8]] (1, 4)\n"
     ]
    }
   ],
   "source": [
    "print(line1, line1.shape)\n",
    "print(line2, line2.shape)\n",
    "print(line3, line3.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1, 77,  3,  4],\n",
       "       [ 5,  6,  7,  8],\n",
       "       [ 9, 10, 11, 12]])"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "KSxCqS2_TGKT"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[77  6 10] (3,)\n",
      "[[77]\n",
      " [ 6]\n",
      " [10]] (3, 1)\n"
     ]
    }
   ],
   "source": [
    "col1 = a[:,1]\n",
    "col2 = a[:, 1:2]\n",
    "\n",
    "print(col1, col1.shape)\n",
    "print(col2, col2.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col2.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 168,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col1.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "xzT-ONxwTO6V"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 4 5]\n"
     ]
    }
   ],
   "source": [
    "t = np.array([[1,2],\n",
    "              [3,4],\n",
    "              [5,6]])\n",
    "\n",
    "print(t[[0,1,2],[0,1,0]]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "DKevt062TSnx"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 4 5]\n"
     ]
    }
   ],
   "source": [
    "print(np.array([t[0,0], t[1,1], t[2,0]]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "2C1i0Ho6TVWR"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3]\n",
      " [ 4  5  6]\n",
      " [ 7  8  9]\n",
      " [10 11 12]]\n"
     ]
    }
   ],
   "source": [
    "s = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "uxySP8koTXlt"
   },
   "outputs": [],
   "source": [
    "indis = np.array([0,2,0,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 2, 0, 1])"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Imc_L_zDTZup"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1  6  7 11]\n"
     ]
    }
   ],
   "source": [
    "print(s[np.arange(4), indis]) #([0,1,2,3],[0,2,0,1]) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "vY8ivMIcTwDX"
   },
   "source": [
    "## Aritmetic Operations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Y3mWYuRMTtp6"
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'np' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-732c4c718d67>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'np' is not defined"
     ]
    }
   ],
   "source": [
    "x = np.array([[1,2],[3,4]], dtype= np.float64)\n",
    "y = np.array([[5,6],[7,8]], dtype= np.float64)\n",
    "\n",
    "\n",
    "print(x+y)\n",
    "\n",
    "print(np.add(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "InoPX9IfT2TD"
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'x' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-fb9c15d00e93>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msubtract\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'x' is not defined"
     ]
    }
   ],
   "source": [
    "print(x-y)\n",
    "\n",
    "print(np.subtract(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "xgjf6TRXT4KE"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 5. 12.]\n",
      " [21. 32.]]\n",
      "[[-4. -4.]\n",
      " [-4. -4.]]\n"
     ]
    }
   ],
   "source": [
    "print(x*y)\n",
    "\n",
    "print(np.subtract(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "L4WmyWO4T7N_"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[19. 22.]\n",
      " [43. 50.]]\n"
     ]
    }
   ],
   "source": [
    "print(np.dot(x,y))  #This function returns the dot product of two arrays."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [],
   "source": [
    "# (2,3) ve (3,2)\n",
    "# (2,2) ve (2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "oGUtI5C2UAzG"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.2        0.33333333]\n",
      " [0.42857143 0.5       ]]\n",
      "[[0.2        0.33333333]\n",
      " [0.42857143 0.5       ]]\n"
     ]
    }
   ],
   "source": [
    "print(x/y)\n",
    "\n",
    "print(np.divide(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "1g4Nst8kUCr9"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2. 3.]\n",
      " [4. 9.]]\n"
     ]
    }
   ],
   "source": [
    "s = np.array([[4,9],[16,81]], dtype = np.float64)\n",
    "\n",
    "print(np.sqrt(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "njZBwrrfUMma"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  16.   81.]\n",
      " [ 256. 6561.]]\n"
     ]
    }
   ],
   "source": [
    "s = np.array([[4,9],[16,81]], dtype = np.float64)\n",
    "\n",
    "print(np.square(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "R6mLUA9lUbri"
   },
   "outputs": [],
   "source": [
    "#Calculate the exponential of all elements in the input array\n",
    "\n",
    "s = np.array([[4,9],[16,81]], dtype = np.float64)\n",
    "print(np.exp(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "J1lL22dDUekL"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 2.30258509  4.60517019  6.90775528  9.21034037 11.51292546 13.81551056]\n"
     ]
    }
   ],
   "source": [
    "v = np.array([10,100,1000,10000,100000,1000000])\n",
    "\n",
    "print(np.log(v))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "BQC2eCOHUglI"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.5      , 1.       , 0.8660254])"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = np.array([np.pi/6, np.pi/2, np.pi/3])\n",
    "\n",
    "np.sin(t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "oLIpPcKzUvBW"
   },
   "source": [
    "## Vector Product"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "OmSpdiGSUjze"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "219\n",
      "219\n"
     ]
    }
   ],
   "source": [
    "x = np.array([[1,2],[3,4]])\n",
    "y = np.array([[5,6],[7,8]])\n",
    "\n",
    "a = np.array([9,10])\n",
    "b = np.array([11,12])\n",
    "\n",
    "\n",
    "print(a.dot(b))\n",
    "\n",
    "print(np.dot(a,b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "EmnpSYU3Uz7f"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[29 67]\n",
      "[39 58]\n"
     ]
    }
   ],
   "source": [
    "print(x.dot(a))\n",
    "\n",
    "print(np.dot(a,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "sYSiH6ezU2oP"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[127 173]\n",
      "[127 173]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(y.dot(b))\n",
    "\n",
    "print(np.dot(y,b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "vsKhePngU4mi"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "[4 6]\n",
      "[3 7]\n"
     ]
    }
   ],
   "source": [
    "x = np.array([[1,2],[3,4]])\n",
    "\n",
    "print(np.sum(x))\n",
    "\n",
    "print(np.sum(x, axis = 0))\n",
    "\n",
    "print(np.sum(x, axis = 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "h9mesia-U7Lt"
   },
   "source": [
    "## Transpose"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "fL-2y6ThVIAs"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 3]\n",
      " [2 4]]\n"
     ]
    }
   ],
   "source": [
    "x = np.array([[1,2],\n",
    "              [3,4]])\n",
    "\n",
    "\n",
    "print(x.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "XA6X8tgmVLPb"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1]\n",
      " [2]\n",
      " [3]]\n"
     ]
    }
   ],
   "source": [
    "v = np.array([[1,2,3]])\n",
    "\n",
    "\n",
    "print(v.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "7WqO52kCVQa1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]]\n",
      "(1, 3)\n",
      "[[1]\n",
      " [2]\n",
      " [3]]\n",
      "(3, 1)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "t = np.array([[1,2,3]])\n",
    "\n",
    "\n",
    "print(t)\n",
    "\n",
    "print(t.shape)\n",
    "\n",
    "print(t.T)\n",
    "\n",
    "v = t.T\n",
    "\n",
    "print(v.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "tcLo6EtbVRQv"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.  2.  2.5]\n",
      "[1 2 2]\n"
     ]
    }
   ],
   "source": [
    "#Data Type Conversion\n",
    "\n",
    "x = np.array([1,2,2.5])\n",
    "\n",
    "print(x)\n",
    "\n",
    "x = x.astype(int)\n",
    "\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "RYPf6IQHVZEW"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2,)\n",
      "(1, 2)\n",
      "(1, 1, 2)\n",
      "(1, 1, 1, 2)\n",
      "<class 'numpy.ndarray'>\n",
      "4\n",
      "[[[[1]]]\n",
      "\n",
      "\n",
      " [[[2]]]]\n"
     ]
    }
   ],
   "source": [
    "#Dimension Expansion\n",
    "\n",
    "y = np.array([1,2])\n",
    "\n",
    "print(y.shape)\n",
    "\n",
    "y = np.expand_dims(y, axis = 0)\n",
    "\n",
    "print(y.shape)\n",
    "\n",
    "y = np.expand_dims(y, axis = 0)\n",
    "\n",
    "print(y.shape)\n",
    "\n",
    "y = np.expand_dims(y, axis = 0)\n",
    "\n",
    "print(y.shape)\n",
    "print(type(y))\n",
    "print(y.ndim)\n",
    "print(y.reshape(2,1,1,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "e24Ud2sKVhg9"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2,)\n",
      "(2, 1)\n",
      "(2, 1, 1)\n",
      "(2, 1, 1, 1)\n"
     ]
    }
   ],
   "source": [
    "x = np.array([1,2])\n",
    "\n",
    "print(x.shape)\n",
    "\n",
    "x = np.expand_dims(x, axis = 1)\n",
    "\n",
    "print(x.shape)\n",
    "\n",
    "x = np.expand_dims(x, axis = 1)\n",
    "\n",
    "print(x.shape)\n",
    "\n",
    "x = np.expand_dims(x, axis = 1)\n",
    "\n",
    "print(x.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Day_7.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
